package cn.tedu.health.service.impl;

import cn.tedu.health.mapper.HealthDataMapper;
import cn.tedu.health.pojo.entity.HealthData;
import cn.tedu.health.service.IHealthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HealthDataService implements IHealthDataService {

    @Autowired
    private HealthDataMapper healthDataMapper;

    @Override
    public void recordHealthData(HealthData healthData) {
        healthDataMapper.insert(healthData);
    }

    @Override
    public HealthData getHealthData(Long userId, LocalDate date) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("date", date);
        return healthDataMapper.findByUserIdAndDate(params);
    }

    @Override
    public List<HealthData> getHealthDataByUserId(Long userId) {
        return healthDataMapper.findByUserId(userId);
    }
}
